#include<bits/stdc++.h>
using namespace std;
#define int long long

int f[400005], w[400005], v[400004], m[400005];

signed main() {
	int n, w_all;
	cin >> n >> w_all;
	for (int i = 1; i <= n; i++)
		cin >> v[i] >> w[i] >> m[i];

	for (int i = 1; i <= n; i++)
		for (int j = w_all; j >= w[i]; j--)
			for (int k = 0; k <= min(m[i], j / w[i]); k++)
				f[j] = max(f[j], f[j - w[i] * k] + v[i] * k);
	cout << f[w_all];
	return 0;
}

